﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using GameFramework.Data;
using GameFramework.DataTable;
using UnityGameFramework.Runtime;

namespace TowerDefence_Zombie.Data
{
    public sealed class LevelData
    {
        private DRLevel dRLevel;
        private WaveData[] waveData;
        private SceneData sceneData;
        private TreasureBoxData treasureBoxData;
        private Dictionary<int, int> towerWeightData;
        private string name;
        private string description;

        public int Id
        {
            get
            {
                return dRLevel.Id;
            }
        }

        public string Name
        {
            get
            {
                return GameEntry.Localization.GetString(dRLevel.NameId);
            }
        }

        public string ResourceGroupName
        {
            get
            {
                return dRLevel.ResourceGroupName;
            }
        }

        public Vector3 PlayerPosition
        {
            get
            {
                return dRLevel.PlayerPosition;
            }
        }

        public Quaternion PlayerQuaternion
        {
            get
            {
                return Quaternion.Euler(dRLevel.PlayerQuaternion);
            }
        }

        public WaveData[] WaveDatas
        {
            get
            {
                return waveData;
            }
        }

        public int[] AllowTowers
        {
            get
            {
                return dRLevel.AllowTowers;
            }
        }

        public int[] TowerWeights
        {
            get
            {
                return dRLevel.TowerWeights;
            }
        }

        public SceneData SceneData
        {
            get
            {
                return sceneData;
            }
        }

        public bool isBossLevel
        {
            get
            {
                return dRLevel.IsBossLevel == 1;
            }
        }

        public int TreasureBoxId
        {
            get
            {
                return dRLevel.TreasureBoxId;
            }
        }

        public TreasureBoxData TreasureBoxData
        {
            get
            {
                return treasureBoxData;
            }
        }

        public int[] UnlockSynthesis
        {
            get
            {
                return dRLevel.UnlockSynthesis;
            }
        }

        public LevelData(DRLevel dRLevel, WaveData[] waveData, SceneData sceneData, TreasureBoxData treasureBoxData)
        {
            this.dRLevel = dRLevel;
            this.waveData = waveData;
            this.sceneData = sceneData;
            this.treasureBoxData = treasureBoxData;
            towerWeightData = new Dictionary<int, int>();
            for (int i = 0; i < AllowTowers.Length; i++)
            {
                if (i >= dRLevel.TowerWeights.Length)
                {
                    Log.Error($"未配置关卡所需炮塔权重 Level == {dRLevel.Id} TowerId == {dRLevel.TowerWeights[i]}");
                    towerWeightData.Add(AllowTowers[i], 0);
                }
                else towerWeightData.Add(AllowTowers[i], dRLevel.TowerWeights[i]);
            }
        }
    }
}
